home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / sun / sources / torast.c < prev   
Encoding:
C/C++ Source or Header  |  1992-12-12  |  1.9 KB  |  76 lines

  1. /*
  2. %    TORAST . C
  3. %
  4. %    convert others to SUN RASTer
  5. %
  6. %    Copyright (c)    Jin Guojun
  7. %
  8. % AUTHOR:    Jin Guojun - LBL    12/12/1991
  9. */
  10.  
  11. #include "header.def"
  12. #include "imagedef.h"
  13.  
  14. arg_fmt_list_string    arg_fmt[] =    {
  15.     {"-a", "%b", True, 1, 0, "add alpha channel"},
  16.     {"-8", "%+ %d", 256, 2, 0,
  17.         "quantizing to 8-bit with # colors [default # %.f]"},
  18.     {"-d", "%-", No, 1, 0, "dither to 8"},
  19.     {"-k", "%b", True, 1, 0, "keep working, and ignore input error"},
  20.     {"-l", "%-", No, 1, 0, "rotate left 90"},
  21.     {"-r", "%+", No, 1, 0, "rotate right 90"},
  22.     {"-u", "%N", RT_STANDARD, 1, 0,
  23.         "use uncompress mode. The default is RLE"},
  24.     {"-o", "%s", No, 1, 1, "output file"},
  25.     {"    [<] input [[> | -o] output]", NULL, 0, 0, 0, "end of usage"},
  26.     NULL    };
  27. U_IMAGE    uimg;
  28. bool    rot, alpha, nostop, pr_t, to8, toN=256;
  29.  
  30. #define    rows    uimg.height
  31. #define    cols    uimg.width
  32.  
  33. main(ac, av)
  34. int    ac;
  35. char*    av[];
  36. {
  37. int    i;
  38. char    **fl, *of_name;
  39.  
  40.     if ((i=parse_argus(&fl, ac, av, arg_fmt,
  41.         &alpha, &to8, &toN, &to8,
  42.         &nostop, &rot, &rot, &pr_t, &of_name)) < 0)
  43.         exit(i);
  44.  
  45.     if (of_name && !(out_fp=freopen(av[++i], "wb", stdout)))
  46.         syserr("output file %s", of_name);
  47.     if (i && !(in_fp=freopen(uimg.name=fl[0], "rb", stdin)))
  48.         syserr("input %s", fl[0]);
  49.  
  50. uimg.color_dpy = alpha ? 1 : -1;
  51. format_init(&uimg, IMAGE_INIT_TYPE, RLE, RAS, *av, "A8-2");
  52.  
  53. io_test(fileno(in_fp), {parse_usage(arg_fmt); exit(0);});
  54.  
  55. if ((*uimg.header_handle)(HEADER_READ, &uimg, 0, 0, True))
  56.     syserr("unknown image type");
  57.  
  58. (*uimg.std_swif)(FI_LOAD_FILE, &uimg, nostop ? NULL : uimg.name, True);
  59.  
  60.     if (rot++) {
  61.     uimg.dest = uimg.src;
  62.     uimg.src = nzalloc(uimg.channels*uimg.width, uimg.height, "rot");
  63.     i = uimg.width;
  64.     uimg.width = uimg.height;
  65.     uimg.height = i;
  66.     color_rotate_90(uimg.dest, uimg.src, i, uimg.width,
  67.         uimg.color_form, rot);
  68.     free(uimg.dest);    uimg.dest = NULL;
  69.     }
  70.     if (uimg.channels>1 && to8)
  71.     To_8(&uimg, reg_cmap, to8>0, toN);
  72.  
  73. (*uimg.std_swif)(FI_SAVE_FILE, &uimg, pr_t, alpha);
  74. exit(0);
  75. }
  76.